$(document).ready(function() {
	var remoteTrans = new Helper.RemoteTrans({
		url:Helper.basePath+"/memberCenter/modifyEmail.htm",
		onError:function(json){
			Helper.message(json.message);
		},
		onSuccess:function(json) {
			if(json.code=="0000"){
				Helper.message("邮箱修改成功");
				location.href=Helper.basePath+"/memberCenter/toPersonSet.htm";
			}else{
				Helper.message("系统繁忙，请稍后重试");
			}
		}
	});
	//修改邮箱
	$("#submit_button").click(function(){
		var old_mail=$("#old_mail").val();
		var password=$("#password").val();
		var new_mail=$("#new_mail").val();
		var re_new_mail=$("#re_new_mail").val();
		
		var validataOldMail=Helper.validata.validataEmail(old_mail);
		if(validataOldMail){
			Helper.message(validataOldMail);
			return ;
		}
		
		var validataNewMail=Helper.validata.validataEmail(new_mail);
		if(validataNewMail){
			Helper.message(validataNewMail);
			return ;
		}
		
		var validataRe_new_mail=Helper.validata.validataEmail(re_new_mail);
		if(validataRe_new_mail){
			Helper.message(validataRe_new_mail);
			return ;
		}
		
		if(new_mail!=re_new_mail){
			Helper.message("两次邮箱不一致");
			return ;
		}
		
		if(password.length<=0){
			Helper.message("密码不可为空");
			return;
		}
		remoteTrans.params = {email:old_mail,password:password,newEmail:new_mail,reNewEmail:re_new_mail};
		remoteTrans.send();
	});
	
	
	//添加邮箱
	var remoteTransAddEmail = new Helper.RemoteTrans({
		url:Helper.basePath+"/memberCenter/addEmail.htm",
		onError:function(json){
			Helper.message(json.message);
		},
		onSuccess:function(json) {
			if(json.code=="0000"){
				Helper.message("添加邮箱成功");
				location.href=Helper.basePath+"/memberCenter/toPersonSet.htm";
			}else{
				Helper.message("系统繁忙，请稍后重试");
			}
		}
	});
	
	
	$("#submit_button_add").click(function(){
		var new_mail=$("#new_mail").val();
		var re_new_mail=$("#re_new_mail").val();
		var password=$("#password").val();
		
		
		var validataNewMail=Helper.validata.validataEmail(new_mail);
		if(validataNewMail){
			Helper.message(validataNewMail);
			return ;
		}
		
		var validataRe_new_mail=Helper.validata.validataEmail(re_new_mail);
		if(validataRe_new_mail){
			Helper.message(validataRe_new_mail);
			return ;
		}
		

		if(new_mail!=re_new_mail){
			Helper.message("两次邮箱不一致");
			return ;
		}
		
		if(password.length<=0){
			Helper.message("密码不可为空");
			return;
		}
		remoteTransAddEmail.params = {email:new_mail,password:password,newEmail:new_mail,reNewEmail:re_new_mail};
		remoteTransAddEmail.send();
	});
	
	
});